package com.hgyc.mom.tool.controller;

import java.util.*;
import jakarta.servlet.http.HttpServletResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import org.springframework.web.multipart.MultipartFile;
import com.hgyc.mom.tool.entity.ToolLabelRecord;
import com.hgyc.mom.tool.vo.ToolLabelRecordParam;
import com.hgyc.mom.tool.service.ToolLabelRecordService;
import com.hgyc.mom.common.vo.Result;
import com.hgyc.mom.common.util.poi.ExcelUtil;

import com.hgyc.mom.core.mybatis.QueryWrapperUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 产品标签记录Controller
 *
 * @author fwj
 * @since 2025-07-24
 */
@Tag(name = "产品标签记录控制器", description = "产品标签记录控制器")
@RestController
@RequestMapping("/tool/label/record")
public class ToolLabelRecordController {
    @Autowired
    private ToolLabelRecordService toolLabelRecordService;

    @Operation(summary = "查询产品标签记录列表", description = "查询产品标签记录列表")
    @PostMapping("/pageList")
    public Result<IPage<ToolLabelRecord>> pageList(@Parameter(description = "查询参数") @RequestBody ToolLabelRecordParam toolLabelRecordParam) {
        Page<ToolLabelRecord> page = new Page<>(toolLabelRecordParam.getPage(), toolLabelRecordParam.getPageSize());
        ToolLabelRecord toolLabelRecord = new ToolLabelRecord();
        BeanUtils.copyProperties(toolLabelRecordParam, toolLabelRecord);
        QueryWrapper<ToolLabelRecord> wrapper = QueryWrapperUtil.build(toolLabelRecord);
        IPage<ToolLabelRecord> list = toolLabelRecordService.page(page, wrapper);
        return Result.success(list);
    }


    @Operation(summary = "获取产品标签记录详细信息", description = "获取产品标签记录详细信息")
    @GetMapping(value = "/{id}")
    public Result getInfo(@Parameter(description = "产品标签记录ID") @PathVariable("id") Long id) {
        return Result.success(toolLabelRecordService.getById(id));
    }
    @Operation(summary = "新增产品标签记录", description = "新增产品标签记录")
    @PostMapping
    public Result<?> save(@Parameter(description = "产品标签记录") @RequestBody ToolLabelRecord toolLabelRecord) {
        toolLabelRecordService.saveRecord(toolLabelRecord);
        return Result.success();
    }

    @Operation(summary = "修改产品标签记录", description = "修改产品标签记录")
    @PutMapping
    public Result<?> update(@Parameter(description = "产品标签记录") @RequestBody ToolLabelRecord toolLabelRecord) {
        toolLabelRecordService.updateRecord(toolLabelRecord);
        return Result.success();
    }

    @Operation(summary = "删除产品标签记录", description = "删除产品标签记录")
    @DeleteMapping
    public Result<?> remove(@Parameter(description = "删除ID") @RequestParam("ids") Long[] ids) {
        return Result.success(toolLabelRecordService.removeByIds(Arrays.asList(ids)));
    }

    @Operation(summary = "导出产品标签记录列表", description = "导出产品标签记录列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ToolLabelRecordParam toolLabelRecordParam) {
        ToolLabelRecord toolLabelRecord = new ToolLabelRecord();
        BeanUtils.copyProperties(toolLabelRecordParam, toolLabelRecord);
        QueryWrapper<ToolLabelRecord> wrapper = QueryWrapperUtil.build(toolLabelRecord);
        List<ToolLabelRecord> list = toolLabelRecordService.list(wrapper);
        ExcelUtil<ToolLabelRecord> util = new ExcelUtil<>(ToolLabelRecord.class);
        util.exportExcel(response, list, "产品标签记录数据");
    }

}
